package com.wl.day44.dao;

import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.wl.day44.model.Book;

public class BookDAOTest {
	SqlSessionFactory factory;
	@Before
	public void setUp() throws Exception {
		Reader reader = Resources.getResourceAsReader("Configuration.xml");
		factory = new SqlSessionFactoryBuilder().build(reader);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testFindAll() {
		SqlSession session = factory.openSession();
		BookDAO dao = session.getMapper(BookDAO.class);
		List<Book> list = dao.findAll();
		session.close();
		for (Book book : list) {
			System.out.println(book.getType().getTypeName());
		}
	}

}
